﻿package sprites {
	import org.flixel.*;
	import flash.display.*;
	import flash.geom.Point;

	/**
	 * ...
	 * @author test
	 */
	public class Fog extends FlxSprite {

		public var size:Number;
		public var csize:Number;

		override public function update():void {
			super.update();
		}

		public function Fog(__player:Player, _size:Number = 100, X:Number = 0, Y:Number = 0, SimpleGraphic:Class = null){
			super(X, Y, SimpleGraphic);
			size = _size;
			csize = new Number(size);
			_player = __player
		}

		private var p_bmd:BitmapData;
		private var cir_bmd:BitmapData;
		public var _player:Player;

		override public function render():void {
			super.render();

			p_bmd = new BitmapData(FlxG.width * 2, FlxG.height * 2, true, 0xff000000);

			var cir_shape:Shape = new Shape;
			cir_shape.graphics.beginFill(0);
			cir_shape.graphics.drawCircle(csize, csize, csize);

			cir_bmd = new BitmapData(cir_shape.width, cir_shape.height, true, 0xffffffff);
			cir_bmd.draw(cir_shape); //可以是任意形状的显示对象
			cir_bmd.copyChannel(cir_bmd, cir_bmd.rect, new Point(), 1, 8);

			var pP:FlxPoint = _player.getScreenXY();
			p_bmd.copyPixels(p_bmd, p_bmd.rect, new Point(pP.x - size + _player.pixels.width / 2, pP.y - size + _player.pixels.height / 2), cir_bmd, new Point(), false);

			/*
			   rec_bmd = new BitmapData(100, 100, true, 0x000000ff);
			   p_bmd.copyPixels(p_bmd, p_bmd.rect, new Point(220, 100), rec_bmd, new Point(), false);
			 */

			FlxG.buffer.draw(new Bitmap(p_bmd));

		}

	}

}